package com.linln.agent.member;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.linln.common.constant.AdminConst;
import com.linln.modules.member.domain.MemberAgent;
import com.linln.modules.member.domain.MemberInfo;
import com.linln.modules.member.service.MemberInfoService;

/**
 * @author hct
 * @date 2019/09/12
 */
@Controller
@RequestMapping("/agent/member")
public class AgentMemberController {

    @Autowired
    private MemberInfoService memberInfoService;

    /**
     * 列表页面
     */
    @GetMapping("/index")
     public String index(Model model,HttpServletRequest request, MemberInfo memberInfo) {

        // 创建匹配器，进行动态查询匹配
       // MemberInfo agent=(MemberInfo)request.getSession().getAttribute(AdminConst.AGENT_ROLE_NAME);
        MemberAgent agent=(MemberAgent)request.getSession().getAttribute(AdminConst.AGENT_AREA_NAME); 
        
        memberInfo.setArea(agent.getArea());              
        // 获取数据列表
        ExampleMatcher matcher = ExampleMatcher.matching();
        Example<MemberInfo> example = Example.of(memberInfo, matcher);
        Page<MemberInfo> list = memberInfoService.getPageList(example);

        // 封装数据
        model.addAttribute("list", list.getContent());
        model.addAttribute("page", list);
        return "/agent/member/index";
    }
 
    /**
     * 跳转到详细页面
     */
    @GetMapping("/detail/{id}")
    public String toDetail(@PathVariable("id") MemberInfo memberInfo, Model model) {
        model.addAttribute("memberInfo",memberInfo);
        return "/agent/member/detail";
    }

    
}